﻿var mongoose = require('mongoose');

var work_overtime_schema = new mongoose.Schema({
    employee_name: { type: String },
    employee_no: { type: String },
    department_name: { type: String },
    position: { type: String },
    month: { type: Number },
    overtime_date: String,
    WeekDay: Number,
    OTDate: Date,
    fare: String,
    memo: String,
    lastModifyDate: Date
});

work_overtime_schema.index({ employee_name: 1, month: 1 });
work_overtime_schema.index({ employee_no: 1, month: 1 });

work_overtime_schema.pre("save", function (next) {    
    this.WeekDay = new Date(this.overtime_date).getDay();
    this.OTDate = new Date(this.overtime_date);
    this.lastModifyDate = Date.now();
    next();
});

module.exports = work_overtime_schema;